package com.company;

public class Main {

    static volatile int j = 0;

    public static void main(String[] args) throws InterruptedException {
        // write your code here
        Thread th1 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    System.out.println("th1.j=" + j);
                    Thread.sleep(1000);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                j++;

            }
        });
        Thread th2 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    System.out.println("th2.j=" + j);
                    Thread.sleep(1000);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                j++;

            }
        });
        th1.start();
        th2.start();
        th1.join();
        th2.join();
        System.out.println(j);

    }
}
